{extend name="public:base"}
{block name="main"}
<div class="demoTable">
  <form class="layui-form" action="">
  <div class="layui-input-inline">
    <a  href="{:Url('cateinfo',array('cateid'=>input('pid')))}" class="layui-btn" data-type="reload" lay-filter="cateadd" lay-submit>添加分类</a>
  </div>

  <div class="layui-input-inline " >
      <select name="pid" lay-filter="select" >
      <option value="0">一级菜单</option>
        {notempty name="catelist"}
        {foreach $catelist as $k=>$v}
        <option value="{$v['cateid']}" {if condition="$info['pid'] eq $v['cateid'] "}selected="selected"{/if}>{$v['catename']}</option>
        {/foreach}
        {/notempty}
      </select>  
  </div>
</div>
<table class="layui-table" lay-data="{height:650,url:location.href,where:{pid:'{:input('pid')}'}, page:true, id:'list'}" lay-filter="table" id="table">
  <thead>
    <tr>
      <th lay-data="{field:'cateid',sort: true,width:65}">ID</th>
      <th lay-data="{field:'catepx',sort: true}">排序</th>
      <th lay-data="{field:'catethumb',templet:'#thumb'}">缩略图</th>
      <th lay-data="{field:'catename'}">分类名称</th>
      <th lay-data="{field:'url',templet:'#link'}">跳转连接</th>
      <th lay-data="{field:'modelname'}">模型</th>
      <th lay-data="{field:'other'}">备注</th>
      <th lay-data="{field:'isnav',templet:'#nav'}">导航</th>
      <th lay-data="{field:'status',templet:'#status'}">状态</th>
      <th lay-data="{field:'addtime'}">添加时间</th>
      <th lay-data="{fixed: 'right',  toolbar: '#barDemo'}">操作</th>
    </tr>
  </thead>
</table>

<!-- <a class="layui-btn layui-btn-sm layui-btn-normal" lay-event="child">子菜单</a> -->

<script type="text/html" id="barDemo">
  
  
  <a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>
   
  <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>
  {{#  if(d.catetype == '单页面'){ }}
      <a class="layui-btn layui-btn-sm" lay-event="editpage">页面编辑</a>
  {{#  } }} 
</script>

<script>
layui.use(['table','laydate','form'], function(){
  var table = layui.table;
  var laydate = layui.laydate;
  var form = layui.form;

   laydate.render({
      elem: '#start',
      max: 0
   });
    laydate.render({
      elem: '#end',
      max: 1
   });
   



  table.on('tool(table)', function(obj){
    var data = obj.data;

   if(obj.event === 'del'){
      layer.confirm('真的删除本条数据吗？', function(index){

        $.post("{:Url('catedel')}",{'cateid': data.cateid},function(data){
           if(data=='1'){
              alert();
              obj.del();
              layer.close(index);
           }else{
             alert("删除失败请重试！");
           }
        })
        
      });
    } else if(obj.event === 'edit'){
        location.href="/admin.php/news/cateinfo/cateid/"+data.cateid;
      //layer.alert('编辑行：<br>'+ JSON.stringify(data))
    } else if(obj.event === 'editpage'){
        location.href="/admin.php/news/pageinfo/cateid/"+data.cateid;
      //layer.alert('编辑行：<br>'+ JSON.stringify(data))
    } else if(obj.event === 'child'){
      location.href="/admin.php/news/catelist/pid/"+data.cateid;
    }/* else if(obj.event === 'content'){
 			
    	console.log(obj.data.catetype);

   		if(obj.data.catetype=='单页面'){

   			location.href="/admin.php/cate/content/cateid/"+data.cateid;

   		}else if(obj.data.catetype=='文章模型'){

   			location.href="/admin.php/cate/newslist/cateid/"+data.cateid;

   		}
       
    }else if(obj.event === 'addcontent'){
    	location.href= "/admin.php/cate/content/cateid/"+data.cateid;
    }*/
    
  });

 //图片查看
  layer.photos({
    photos: 'div'
    ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
  });

  //开关
  form.on('switch(status)', function(data){

    var name=$(this).attr('name');

    $.post("{:url('cateup')}",{type:name,value:data.elem.checked,'cateid':data.value},function(res){
      if(res=='0'){
        alert("操作失败");
      }
    });
   
  });  

  //下拉选择
  form.on('select(select)', function(data){

    table.reload('list', {
      url: location.href
      ,where: {
         pid:data.value
      } 
      
    });

  });      
    

});
</script>

<script type="text/html" id="link">
  {{#  if(d.url != '' && typeof(d.url) != 'undefined'){ }}
     <a href="{{d.url}}" class="layui-table-link" target="_blank">{{d.url}}</a>
  {{#  } }}
</script>
<script type="text/html" id="thumb">
  <img src='{{d.src}}' >
</script>
<script type="text/html" id="status">
  {{#  if(d.status == 1){ }}
    <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|禁用" lay-filter="status" value="{{d.cateid}}" checked>
  {{#  } else { }}
    <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|禁用" lay-filter="status"  value="{{d.cateid}}">
  {{#  } }}
</script>
<script type="text/html" id="nav">
  {{#  if(d.isnav == 1){ }}
    <input type="checkbox" name="isnav" lay-skin="switch" lay-text="显示|隐藏" lay-filter="status" value="{{d.cateid}}" checked>
  {{#  } else { }}
    <input type="checkbox" name="isnav" lay-skin="switch" lay-text="显示|隐藏" lay-filter="status"  value="{{d.cateid}}">
  {{#  } }}
</script>



{/block}